<%@ include file="/common/taglibs.jsp"%>
<title><fmt:message key="appRoleDetail.heading"/></title>
<content tag="buttons">
	<probiz:iconBtn btnType="save" onclick="saveRole()" />
	<c:if test="${!appRole.isSuperAdminRole}">
		<probiz:iconBtn btnType="delete" onclick="fnDoDelete(this)"/>
	</c:if>
	<probiz:iconBtn btnType="back" url="${ctxPath}/system/adminRole.html" />
</content>
<probiz:showBindErrors bindPath="appRole.*" />
<div class="top clearfix">
	<ul class="tab">
		<li class="curr"><span>
			<fmt:message key="appRoleDetail.heading"/>
			</span></li>
	</ul>
</div>
<div class="modify">
	<form class="mainForm" method="post" action="<c:url value="/system/adminRole.html?doAction=save"/>" id="appRole"
	onsubmit="return validateAppRole(this)">
		<input type="hidden" name="doAction" value=""/>
		<input type="hidden" id="appRoleId" name="appRoleId" value="${appRole.roleId}"/>
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="com_modi_table">
			<tr>
				<th colspan="2" class="title">
					<h4>
						<fmt:message key="appRole.group.roleInfo"/>
					</h4>
				</th>
			</tr>
			<tr>
				<th class="label_width_1">
					<StoreAdmin:label key="appRole.roleName"/>
				</th>
				<td>
					<spring:bind path="appRole.roleName">
						<c:if test="${empty appRole.roleId}">
							<input class="inputtext field200" type="text" name="${status.expression}" size="38" id="${status.expression}" value="${status.value}"/>
						</c:if>
						<c:if test="${not empty appRole.roleId }"> ${appRole.roleName}
							<input type="hidden" name="roleName" value="${status.value}"/>
						</c:if>
					</spring:bind>
				</td>
			</tr>
			<tr>
				<th>
					<StoreAdmin:label key="appRole.roleDetail"/>
				</th>
				<td>
					<spring:bind path="appRole.roleDetail">
						<textarea cols="60" rows="4" id="${status.expression}" name="${status.expression}">${status.value}</textarea>
						<span class="fieldError"><c:out value="${status.errorMessage}"/></span>
					</spring:bind>
				</td>
			</tr>
		</table>
		<br/>
		<br/>
		<c:if test="${!appRole.isSuperAdminRole}">
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="com_modi_table">
				<tr class="closer">
					<td colspan="2">
						<div class="warning_msg">
							<fmt:message key="appRoleDetail.menu.info1"/><br/>
							<fmt:message key="appRoleDetail.menu.info2"/>
						</div>
					</td>
				</tr>
				<tr>
					<td width="50%">
						<table width="100%">
							<tr>
								<th class="title"> <h4 style="padding:3px 10px"><fmt:message key="appRole.grant.menu" /></h4></th>
							</tr>
							<tr>
								<td>
									<ul class="tree" style="margin-left:40px;">
										<c:forEach items="${allMenus}" var="pms">
											<c:choose>
												<c:when test="${pms.menuId == 1}">
													<%-- 主面板不需要checkbox --%>
													<label title="${pms.title}<c:if test="${not empty pms.url}">(${pms.url})</c:if>">${pms.title}</label>
												</c:when>
												<c:otherwise>
													<li>
														<input type="checkbox" name="ckMenuId" value="${pms.menuId}"  ${appRole.roleName eq DEFAULT_ADMIN_ROLE_NAME?'disabled="true"':''}/>
														<label title="${pms.title}<c:if test="${not empty pms.url}">(${pms.url})</c:if>">${pms.title}</label>
														<ul><c:forEach items="${pms.children}" var="sms">
															<li>
																<input type="checkbox" name="ckMenuId" value="${sms.menuId}" ${appRole.roleName eq DEFAULT_ADMIN_ROLE_NAME?'disabled="true"':''}/>
																<label title="${sms.title}<c:if test="${not empty sms.url}">(${sms.url})</c:if>">${sms.title}</label>
																<ul><c:forEach items="${sms.children}" var="rs">
																	<li>
																		<input type="checkbox" name="ckMenuId" value="${rs.menuId}" ${appRole.roleName eq DEFAULT_ADMIN_ROLE_NAME?'disabled="true"':''}/>
																		<label title="${rs.title}<c:if test="${not empty rs.url}">(${rs.url})</c:if>">${rs.title}</label>
																	</li></c:forEach>
																</ul>
															</li></c:forEach>
														</ul>
													</li>
												</c:otherwise>
											</c:choose>	
										</c:forEach>
									</ul>
									<c:if test="${empty allMenus}"><fmt:message key="appRole.noMenus" /></c:if>
								</td>
							</tr>
						</table>
					</td>
					<td width="50%">
						<table width="100%">
							<tr>
								<th class="title"> <h4 style="padding:3px 10px"><fmt:message key="appRole.grant.resource" /></h4></th>
							</tr>
							<tr>
								<td>
									<ul class="tree" style="margin-left:40px;"><c:forEach items="${allRess}" var="pms">
										<li>
											<input type="checkbox" name="ckMenuId" value="${pms.menuId}"  ${appRole.roleName eq DEFAULT_ADMIN_ROLE_NAME?'disabled="true"':''}/>
											<label title="${pms.title}<c:if test="${not empty pms.url}">(${pms.url})</c:if>">${pms.title}</label>
											<ul><c:forEach items="${pms.children}" var="sms">
												<li>
													<input type="checkbox" name="ckMenuId" value="${sms.menuId}" ${appRole.roleName eq DEFAULT_ADMIN_ROLE_NAME?'disabled="true"':''}/>
													<label title="${sms.title}<c:if test="${not empty sms.url}">(${sms.url})</c:if>">${sms.title}</label>
													<ul><c:forEach items="${sms.children}" var="rs">
														<li>
															<input type="checkbox" name="ckMenuId" value="${rs.menuId}" ${appRole.roleName eq DEFAULT_ADMIN_ROLE_NAME?'disabled="true"':''}/>
															<label title="${rs.title}<c:if test="${not empty rs.url}">(${rs.url})</c:if>">${rs.title}</label>
														</li></c:forEach>
													</ul>
												</li></c:forEach>
											</ul>
										</li></c:forEach>
									</ul>
									<c:if test="${empty allMenus}"><fmt:message key="appRole.noResources" /></c:if>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</c:if>
	</form>
</div>
<v:javascript formName="appRole" staticJavascript="false"/>

<c:set var="plugin_checkTree" value="true" scope="request"/>
<script type="text/javascript">
var selMenuIds=new Array();
<c:forEach items="${appRole.appMenus}" var="rs" varStatus="i">
	selMenuIds[${i.index}]=${rs.menuId};
</c:forEach>

window.onload=function(){
	var ckMenuIds=document.getElementsByName("ckMenuId");
	for(var i=0;i<selMenuIds.length;i++){
		for(var j=0;j<ckMenuIds.length;j++){
			if(selMenuIds[i]==ckMenuIds[j].value){
				ckMenuIds[j].checked=true;
				break;
			}
		}
	}
	$j("ul.tree").checkTree({});
}

//保存
function saveRole(){
	if(!validateAppRole()){
    	return ;
    }
    var postData="";
    postData += $j('#appRole :input').serialize();
    var url=$j('#appRole').attr('action');
    $j.post(url,postData,saveRoleCallback,"json");
}
//保存回调函数
function saveRoleCallback(data){
	sysMsg(data.message,data.error);
	if(data.appRoleId){
		$j("#appRoleId").val(data.appRoleId);
	}
	if(data.isDeleteable){
		enableIconBtn("delete");
	}
}
</script>